//@author wtfumlomglol
package amm.Graphic;

import java.io.*;
import java.util.*;

//a kozlekedesi lampakat leiro osztaly
public class TrafficLight implements ITickable {

    //a lampa szine
    private boolean isGreen = false;
    //referencia az iranyitoegysegre
    private LightController lc;
    //a zold allapot hatralevo idejet jelzi
    private int greenCounter = 0;

    public TrafficLight(LightController lContr)
    {
        lc=lContr;
    }

    //szinvaltas metodus
    public void swapColour() {
        //ha piros
        if (!isGreen) {
            greenCounter = 4;
            isGreen = true;
        }
        //ha zold
        else {
            isGreen = false;
        } 
    }

    //a lampanak egy kore
    public void onTick() {
        //ha zold
        if (isGreen)
        {
            //csokkenti az idot
            greenCounter--;
            //ha elerte a nullat, szol az iranyitoegysegnek
            if (greenCounter==0)
            {
                lc.notifyLC();
            }
        }
        //piros allapot eseten azonnal passzolja a kort
    }

    public boolean getColour() {
        return isGreen;
    }

    public void setColour(boolean colour)
    {
        isGreen=colour;
        if (colour) greenCounter=4;
    }
}
